<?php
// Tim'Roster
// Copyright (c) 2011 Nicolas Nallet <aspgic2@gmail.com>
//
// This file is part of Tim'Roster.
//
// Tim'Roster is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Tim'Roster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA



$xml_config = simplexml_load_file('config.xml');

include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Item_Base.php');
include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Enum/Enum_Item_Type.php');
include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Enum/Enum_Item_Class.php');

class Material_Item extends Item_Base {

    /**
     * (PHP 5)<br/>
     * Construct a Material_Item instance
     * @param int $guild_id
     * @param int $id
     * @param string $code
     * @param string $name
     * @param int $quality
     * @param int $quantity
     * @param int $ecosystem_id
     * @param string $guild_name
     */
    public function Material_Item($guild_id, $id, $code, $name, $quality, $quantity, $ecosystem_id, $guild_name){
        
        $this->ecosystem_id = $ecosystem_id;
        $item_class = Enum_Item_Class::convert_api_code_to_id(substr($code, 9, 3));

        if ($code == 'ixpca01.sitem'){
            $item_type_id = Enum_Item_Type::ELEVATION_CRYSTAL_ITEM_TYPE_ID;
        }
        else
        {
            if (strpos($code,'dxa') == true) {
                $item_type_id = Enum_Item_Type::HARVESTED_ITEM_TYPE_ID;
            }
            else {
                $item_type_id = Enum_Item_Type::LOOTED_ITEM_TYPE_ID;
                //looted material class is strangely coded, between a01 to e01.
                //for harvested item, the class is between b01 and f01
                //so in order to have the right class we just add 1 to the current item_class
                $item_class += 1;
            }
        }

        parent::Item_Base($guild_id, $id, $code, $name, $quality, $quantity, $item_type_id, $item_class, $guild_name);
    }

    private $ecosystem_id;
    /**
     * (PHP 5)<br/>
     * Get item ecosystem int
     * @return int
     */
    public function get_ecosystem_id(){
        return $this->ecosystem_id;
    }
    /**
     * (PHP 5)<br/>
     * Get item ecosystem label
     * @return string
     */
    public function get_ecosystem_label(){
        return Enum_Ecosystem::convert_id_to_label($this->ecosystem_id);
    }

    /**
     * (PHP 5)<br/>
     * Get item order
     * @return int
     */
    public function get_order(){
        return $this->ecosystem_id;
    }
}

?>
